﻿using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlotDesigner
{
    public partial class SpeakerListEditor : Form
    {
        public SpeakerListEditor()
        {
            InitializeComponent();
        }

        void refreshList()
        {
            listBox1.Items.Clear();
            foreach(string s in Source.speakerList)
            {
                listBox1.Items.Add(s);
            }
        }
        private void SpeakerListEditor_Load(object sender, EventArgs e)
        {
            refreshList();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            string speaker = Interaction.InputBox("请输入新的说话人姓名：", "新增说话人", "");
            if (speaker == "") return;
            Source.speakerList.Add(speaker);
            refreshList();
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex == -1) return;
            if(MessageBox.Show("确定要删除吗？", "删除说话人", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Source.speakerList.RemoveAt(listBox1.SelectedIndex);
                refreshList();
            }
        }
    }
}
